package com.itbour.web.action.yjx.trade;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.itbour.com.page.Page;
import com.itbour.common.base.BaseAction;
import com.itbour.common.util.StringUtils;
import com.itbour.dto.com.UserInfoDto;
import com.itbour.dto.yjx.trade.YjxFeedbackFromDto;
import com.opensymphony.xwork2.ActionContext;
import com.itbour.service.yjx.trade.YjxFeedbackFromService;

public class GetYjxFeedbackInfoAction extends BaseAction{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private YjxFeedbackFromService yjxFeedbackFromService;
	private String findFebType;//获取反馈类型
	private HashMap<String, Object> yjxFeedbackMapResult = new HashMap<String, Object>();//分页反馈信息列表
	private List<YjxFeedbackFromDto> yjxFeedbackInfoList;// 反馈信息列表
	private YjxFeedbackFromDto yjxFeedbackInfo;// 更新用
	private String fb_id;// 用户反馈id
	private List<YjxFeedbackFromDto> yjxFbFromList;// 反馈来源
	private String findFbFrom;// 检索条件反馈来源
	private String findFbState;// 检索条件反馈状态
	private String findFbMobile;// 检索条件手机号
	private String ids;
	
	
	public String getIds() {
		return ids;
	}
	public void setIds(String ids) {
		this.ids = ids;
	}
	public YjxFeedbackFromService getYjxFeedbackFromService() {
		return yjxFeedbackFromService;
	}
	public void setYjxFeedbackFromService(
			YjxFeedbackFromService yjxFeedbackFromService) {
		this.yjxFeedbackFromService = yjxFeedbackFromService;
	}
	public String getFindFebType() {
		return findFebType;
	}
	public void setFindFebType(String findFebType) {
		this.findFebType = findFebType;
	}
	public HashMap<String, Object> getYjxFeedbackMapResult() {
		return yjxFeedbackMapResult;
	}
	public void setYjxFeedbackMapResult(HashMap<String, Object> yjxFeedbackMapResult) {
		this.yjxFeedbackMapResult = yjxFeedbackMapResult;
	}
	public List<YjxFeedbackFromDto> getYjxFeedbackInfoList() {
		return yjxFeedbackInfoList;
	}
	public void setYjxFeedbackInfoList(List<YjxFeedbackFromDto> yjxFeedbackInfoList) {
		this.yjxFeedbackInfoList = yjxFeedbackInfoList;
	}
	public YjxFeedbackFromDto getYjxFeedbackInfo() {
		return yjxFeedbackInfo;
	}
	public void setYjxFeedbackInfo(YjxFeedbackFromDto yjxFeedbackInfo) {
		this.yjxFeedbackInfo = yjxFeedbackInfo;
	}

	public String getFb_id() {
		return fb_id;
	}
	public void setFb_id(String fb_id) {
		this.fb_id = fb_id;
	}
	public List<YjxFeedbackFromDto> getYjxFbFromList() {
		return yjxFbFromList;
	}
	public void setYjxFbFromList(List<YjxFeedbackFromDto> yjxFbFromList) {
		this.yjxFbFromList = yjxFbFromList;
	}
	public String getFindFbFrom() {
		return findFbFrom;
	}
	public void setFindFbFrom(String findFbFrom) {
		this.findFbFrom = findFbFrom;
	}
	public String getFindFbState() {
		return findFbState;
	}
	public void setFindFbState(String findFbState) {
		this.findFbState = findFbState;
	}
	public String getFindFbMobile() {
		return findFbMobile;
	}
	public void setFindFbMobile(String findFbMobile) {
		this.findFbMobile = findFbMobile;
	}
	
	
	public String getFeedbackInfoPg() throws Exception {
		// 用户信息
		Map<String, Object> session = ActionContext.getContext().getSession();
    	UserInfoDto user = (UserInfoDto)session.get("user");
    	
		HttpServletRequest request = ServletActionContext.getRequest();
		String pageNumber = request.getParameter("page");
		String pageSize = request.getParameter("rows");
		
		Map<String, Object> param = new HashMap<String, Object>();
		if (StringUtils.isNotBlank(findFbFrom)) {
			param.put("from", findFbFrom);
		}
		if (StringUtils.isNotEmpty(findFbMobile)) {
			param.put("mobile", "%"+findFbMobile+"%");
		}
		if (StringUtils.isNotBlank(findFbState)) {
			param.put("state", findFbState);
		}
		if (StringUtils.isNotBlank(findFebType)){
			param.put("fb_type", findFebType);
		}
		Page page = yjxFeedbackFromService.feedbackPgQuery(param,
				Integer.parseInt(pageNumber),
				Integer.parseInt(pageSize));
		HashMap<String, Object> resMap = new HashMap<String, Object>();
		resMap.put("total", page.getTotalCount());
		resMap.put("rows", page.getResult());
		yjxFeedbackMapResult = resMap;
		return SUCCESS;
	}
	
	

	// 获取用户反馈信息列表
	public String getFeedbackInfoList() throws Exception {
		HttpServletRequest request = ServletActionContext.getRequest();
		Map<String, Object> param = new HashMap<String, Object>();
		String fb_id = request.getParameter("fb_id");
		if (StringUtils.isNotEmpty(fb_id)) {
			param.put("fb_id", fb_id);
		}
		yjxFeedbackInfoList = yjxFeedbackFromService.selectFeedbackInfo(param);
		return SUCCESS;
	}
	
	// 删除用户反馈
	public void delFeedback() throws Exception {
		yjxFeedbackFromService.delFeedback(ids);
		this.writeJSON("ok");
	}
	
	// 更新用户反馈
	public void updFeedback() throws Exception {
		if (yjxFeedbackInfo != null && yjxFeedbackInfo.getFb_id()!=null) {
			Map<String, Object> session = ActionContext.getContext().getSession();
	    	UserInfoDto user = (UserInfoDto)session.get("user");
	    	if(user != null && user.getUser_id()>0) {
	    		Map<String, Object> param = new HashMap<String, Object>();
		    	param.put("fb_id", yjxFeedbackInfo.getFb_id());
	    		param.put("update_by", user.getUser_id());
	    		if(yjxFeedbackInfo.getState() != null) {
		    		param.put("state", yjxFeedbackInfo.getState());
		    	}
		    	if(yjxFeedbackInfo.getNote() != null) {
		    		param.put("note", yjxFeedbackInfo.getNote());
		    	}
		    	
		    	yjxFeedbackFromService.updFeedback(param);
				this.writeJSON("ok");
				
	    	} else {
				this.writeJSON("ng");
			}
		} else {
			this.writeJSON("ng");
		}
	}
	
	// 获取反馈来源
	public String getFbFrom4Combo() throws Exception {
		HttpServletRequest request = ServletActionContext.getRequest();
		String flg = request.getParameter("blkFlg");
		Map<String, Object> param = new HashMap<String, Object>();
		yjxFbFromList = yjxFeedbackFromService.getFeedbackFrom4Combo(param);
		if(yjxFbFromList != null && yjxFbFromList.size()>0){
			// 添加空白项目
			if("1".equals(flg)){
				YjxFeedbackFromDto yjxFeedbackInfo = new YjxFeedbackFromDto();
				yjxFeedbackInfo.setFrom_value("");
				yjxFeedbackInfo.setFrom_text("[不限]");
				yjxFbFromList.add(0, yjxFeedbackInfo);
			}
		}
		return SUCCESS;
	}
	
}
